package me.leiusual.sharing.ui.home

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations.switchMap
import androidx.lifecycle.ViewModel
import androidx.paging.PagedList
import me.leiusual.sharing.api.model.storesearch.StoreContent
import me.leiusual.sharing.repository.StoreRepository
import javax.inject.Inject

/**
 * author: leiusual
 * create on: 2019-07-30
 * description:
 */
class HomeSearchStoreViewModel @Inject constructor(
    private val storeRepository: StoreRepository
) : ViewModel() {

  // 店铺搜索

  private val _storeSearch = MutableLiveData<String>()
  val storeSearch: LiveData<PagedList<StoreContent>> = switchMap(_storeSearch) {
    storeRepository.storeSearch(it)
  }

  fun storeSearch(keyword: String) {
    _storeSearch.value = keyword
  }
}